package com.ruoyi.web.controller.mall;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserCoupons;
import com.ruoyi.system.service.IUserCouponsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 顾客优惠券Controller
 * 
 * @author ruoyi
 * @date 2024-03-22
 */
@Controller
@RequestMapping("/mall/userCoupons")
public class UserCouponsController extends BaseController
{
    private String prefix = "mall/userCoupons";

    @Autowired
    private IUserCouponsService userCouponsService;

    @RequiresPermissions("mall:userCoupons:view")
    @GetMapping()
    public String userCoupons()
    {
        return prefix + "/userCoupons";
    }

    /**
     * 查询顾客优惠券列表
     */
    @RequiresPermissions("mall:userCoupons:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserCoupons userCoupons)
    {
        startPage();
        List<UserCoupons> list = userCouponsService.selectUserCouponsList(userCoupons);
        return getDataTable(list);
    }

    /**
     * 导出顾客优惠券列表
     */
    @RequiresPermissions("mall:userCoupons:export")
    @Log(title = "顾客优惠券", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserCoupons userCoupons)
    {
        List<UserCoupons> list = userCouponsService.selectUserCouponsList(userCoupons);
        ExcelUtil<UserCoupons> util = new ExcelUtil<UserCoupons>(UserCoupons.class);
        return util.exportExcel(list, "顾客优惠券数据");
    }

    /**
     * 新增顾客优惠券
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存顾客优惠券
     */
    @RequiresPermissions("mall:userCoupons:add")
    @Log(title = "顾客优惠券", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserCoupons userCoupons)
    {
        return toAjax(userCouponsService.insertUserCoupons(userCoupons));
    }

    /**
     * 修改顾客优惠券
     */
    @RequiresPermissions("mall:userCoupons:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UserCoupons userCoupons = userCouponsService.selectUserCouponsById(id);
        mmap.put("userCoupons", userCoupons);
        return prefix + "/edit";
    }

    /**
     * 修改保存顾客优惠券
     */
    @RequiresPermissions("mall:userCoupons:edit")
    @Log(title = "顾客优惠券", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserCoupons userCoupons)
    {
        return toAjax(userCouponsService.updateUserCoupons(userCoupons));
    }

    /**
     * 删除顾客优惠券
     */
    @RequiresPermissions("mall:userCoupons:remove")
    @Log(title = "顾客优惠券", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userCouponsService.deleteUserCouponsByIds(ids));
    }
}
